package com.ynet.middleground.approve.mq.producer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.approve.mq.Source;

/**
 * @author liulx
 * @description 合约中心模板状态消息发布
 * @date 2020-04-28 14:13
 */
@EnableBinding({Source.class})
@Component
public class ContractTemplateProducer {

    // String tag = "tag_contact_template";
    String tag = "tag1";
    String tag2 = "tag2";

    @Autowired
    private Source source;

    /**
     * 发送修改合约状态模板消息
     * 
     * @param templateIds
     *            待激活/停用的模板列表
     * @param templateStatus
     *            合约模板状态码: 1: 启用中, 2: 激活模板, 3: 停用模板
     * @param channel
     *            渠道标志
     */
    public void sendMessages(List<Integer> templateIds, Object templateStatus, String channel,
        Integer operationUserId) {
        Map<String, Object> msgMap = new HashMap<>(4);
        msgMap.put("templateStatus", templateStatus);
        msgMap.put("channel", channel);
        msgMap.put("operationUserId", operationUserId);
        msgMap.put("templateIds", templateIds);
        IfpLogger.info("mq", "往 Binding-{} 推送信息-{}", Source.O_CONTRACT, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        headers.put("TAGS", tag);
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.source.noticeContract().send(message);
    }

}
